package com.shop.cereshop.business.dl.logic.service.Impl;

import com.shop.cereshop.business.dl.logic.domain.CereShopImportTicketLog;
import com.shop.cereshop.business.dl.logic.service.CereShopImportTicketLogService;
import com.shop.cereshop.business.dl.logic.service.SendPostImpl;
import com.shop.cereshop.business.dl.logic.service.TicketingImportService;
import com.shop.cereshop.business.dl.logic.utils.JsonUtils;
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @description
 * @Author YF
 * @Date 日期:2021/6/16 时间:9:50
 */
@Service
public class TicketingImportServiceImpl implements TicketingImportService {

    @Autowired
    private SendPostImpl sendPost;
    @Autowired
    private AddDataImpl addDataImpl;
    @Autowired
    private CereShopImportTicketLogService cereShopImportTicketLogService;


    /**
     * @description:导入票务
     * @return:
     * @author:作者:YF
     * @time:日期:2021/6/16 时间:9:55
     */
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = {CoBusinessException.class, Exception.class})
    @Override
    public void setShopProductAll(String productNo, CerePlatformBusiness user) throws CoBusinessException {
        //1.根据平台产品编号获得产品
        String productInfo = sendPost.GetProductInfo(1, 100, productNo, null, null);
        //2.根据json转成map
        Map<?, ?> map = JsonUtils.toMap(productInfo);
        //3.获得productList参数集合
        List list = (List) map.get("productList");
        //添加日志
        CereShopImportTicketLog cereShopImportTicketLog = new CereShopImportTicketLog();
        cereShopImportTicketLog.setCreateTime(TimeUtils.yyMMddHHmmss());
        cereShopImportTicketLog.setProductInfo(productInfo);
        cereShopImportTicketLogService.insertSelective(cereShopImportTicketLog);
        //0.判断productNo是否为空,如果不为空，则是一条数据，如果为空则是全部数据
        if (productNo!=null){

//              list = (List) map.get("productList");
            Object result = list.get(0);
            addDataImpl.AddData(result,user);
        }else {
//            //1.根据平台产品编号获得产品
//            String productInfo = sendPost.GetProductInfo(1, 100, productNo, null, null);
//            //2.根据json转成map
//            Map<?, ?> map = JsonUtils.toMap(productInfo);
//            //3.获得productList参数集合
//            List list = (List) map.get("productList");
            addDataImpl.AddList(list,user);
        }


    }








}
